<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            height: 100px;
            margin: 100px auto;
        }
        input {
            width: 60%;
            outline: none;
        }
        span {
            font-size: 12px;
        }
        .right {
            color: skyblue;
        }
        .fls {
color: red;
        }
    </style>
</head>
<body>
    <div class="box">
        <input type="text"> <span>输入用户名</span>
    </div>
    <script>
        var input = document.querySelector('input')
        var span = document.querySelector('span')
        var rep = /^[a-zA-Z@_-]{6,12}$/
        input.addEventListener('blur',function(){
            if( rep.test(this.value)){
                span.innerText = '输入正确'
                span.className = 'right'
            }else{
                span.innerText = '输入错误'
                span.className = 'fls'
            }
         
        })
    </script>
</body>
</html>